import re

def parse_column_name_string_uk(s):
    # Initialize default values
    field_id = None
    instance_index = None
    array = None

    # Extract array (last _a followed by digits)
    array_match = re.search(r'_a(\d+)$', s)
    if array_match:
        array = int(array_match.group(1))
        s = s[:array_match.start()]  # Remove array part from string

    # Extract instance_index (last _i followed by digits)
    instance_match = re.search(r'_i(\d+)$', s)
    if instance_match:
        instance_index = int(instance_match.group(1))
        s = s[:instance_match.start()]  # Remove instance_index part from string

    # Extract field_id (everything after 'p')
    if s.startswith('p'):
        field_id = s[1:] if s[1:] else None

    return field_id, instance_index, array

if __name__ == '__main__':

    # Test cases
    test_cases = [
        "phla_dra_i2",
        "phla_e_i2",
        "p1234_i1_a1",
        "p1234_a2",
        "pebi3_il27_i0",
        "pebi3_il27",
        "pifnl2_i0",
        "pifnl2_a2",
        "pifnl2_asa2",
        "pifnl2_asa2_i1_a2",
        "pifnl2_asa2_i1",
        "pebi3_il27_i0",
        "phsd17b14_i0"

    ]

    for test in test_cases:
        field_id, instance_index, array = parse_column_name_string_uk(test)
        print(f"Input: {test}")
        print(f"field_id: {field_id}, instance_index: {instance_index}, array: {array}\n")